package cn.cs.service.impl;

import cn.cs.client.ComplaintTitleClient;
import cn.cs.common.Constants;
import cn.cs.common.EmptyUtils;
import cn.cs.common.Page;
import cn.cs.pojo.ComplaintTitle;
import cn.cs.service.ComplaintTitleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class ComplaintTitleServiceImpl implements ComplaintTitleService {

    @Resource
    private ComplaintTitleClient complaintTitleClient;

    public ComplaintTitle getComplaintTitleById(String id) throws Exception {
        return complaintTitleClient.getComplaintTitleById(id);
    }

    public List<ComplaintTitle> getComplaintTitleListByMap(Map<String, Object> param) throws Exception {
        return complaintTitleClient.getComplaintTitleListByMap(param);
    }

    public Integer getComplaintTitleCountByMap(Map<String, Object> param) throws Exception {
        return complaintTitleClient.getComplaintTitleCountByMap(param);
    }

    public Integer addComplaintTitle(ComplaintTitle complaintTitle) throws Exception {
        return complaintTitleClient.addComplaintTitle(complaintTitle);
    }

    public Integer modifyComplaintTitle(ComplaintTitle complaintTitle) throws Exception {
        return complaintTitleClient.modifyComplaintTitle(complaintTitle);
    }

    public Integer deleteComplaintTitleById(String id) throws Exception {
        return complaintTitleClient.deleteComplaintTitleById(id);
    }

    public Page<ComplaintTitle> queryComplaintTitlePageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) throws Exception {
        Integer total = complaintTitleClient.getComplaintTitleCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<ComplaintTitle> complaintTitleList = complaintTitleClient.getComplaintTitleListByMap(param);
        page.setRows(complaintTitleList);
        return page;
    }

}
